<template>
    <!-- <div @dragstart="handleDragStart" class="component-list">
        <div v-for="(item, index) in componentList" :key="index" class="list" draggable :data-index="index">
            <span class="iconfont" :class="'icon-' + item.icon"></span>
            <span>{{ item.label }}</span>
        </div>
    </div> -->
    <div>
        <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="基本" name="base">
                <div @dragstart="handleDragStart" class="component-list">
                    <div v-for="(item, index) in componentList" :key="index" class="list" draggable :data-index="index">
                        <span class="iconfont" :class="'icon-' + item.icon"></span>
                        <span>{{ item.label }}</span>
                    </div>
                </div>
            </el-tab-pane>
            <el-tab-pane label="点配置" name="point">
                <div @dragstart="handleDragStart" class="component-list">
                    <div v-for="(item, index) in pointList" :key="index" class="list" draggable :data-index="index">
                        <span>{{ item.pointDes }}</span>
                    </div>
                </div>
            </el-tab-pane>
        </el-tabs>
    </div>
</template>

<script>
import componentList from '@/custom-component/component-list'
import pointList from '@/custom-component/point'
import eventBus from '@/utils/eventBus'

export default {
    data() {
        return {
            componentList,
            pointList,
            activeName: 'base',
        }
    },
    mounted() {
    },
    methods: {
        handleDragStart(e) {
            e.dataTransfer.setData('index', e.target.dataset.index)
        },
        handleClick(tab) {
            eventBus.$emit('tab-name', tab.name)
        },
    },
}
</script>

<style lang="scss" scoped>
.component-list {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 10px;

    .list {
        width: 80%;
        margin-left: 10%;
        border: 1px solid #ddd;
        cursor: grab;
        margin-bottom: 10px;
        text-align: center;
        color: #333;
        padding: 2px 5px;
        display: flex;
        align-items: center;
        justify-content: center;

        &:active {
            cursor: grabbing;
        }

        .iconfont {
            margin-right: 4px;
            font-size: 20px;
        }

        .icon-wenben,
        .icon-tupian {
            font-size: 18px;
        }
    }
}
</style>